package cn.lg.soar.system.biz.modules.auth.model;

import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.database.base.entity.PathTreeEntity;
import cn.lg.soar.system.biz.modules.auth.entity.Post;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 岗位(职位)
 * @author luguoxiang
 * @date 2021/9/11
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class PostDto extends PathTreeEntity {

    private static final long serialVersionUID = -4449119630824641083L;

    @NotNull(message = "id不能为空", groups = {Update.class})
    @Min(value = 0, message = "id不能小于0", groups = {Update.class})
    @Schema(description = "id")
    private Long id;

    @NotNull(message = "机构不能为空", groups = {Create.class})
    @Schema(description = "岗位所属机构")
    private Long orgId;

    @NotBlank(message = "名称不能为空", groups = {Create.class})
    @Schema(description = "名称")
    private String name;

    @Schema(description = "别名")
    private String alias;

    @Schema(description = "描述")
    private String remark;

    @Schema(description = "权限角色")
    private List<Long> roleIds;

    @Schema(description = "标签")
    private List<Long> tagIds;

    @Override
    public Long primaryKey() {
        return this.id;
    }

    public PostDto() {
    }

    public PostDto(Post source) {
        this.id = source.getId();
        this.orgId = source.getOrgId();
        this.name = source.getName();
        this.alias = source.getAlias();
        this.remark = source.getRemark();
        this.setCreateTime(source.getCreateTime());
        this.setCreateBy(source.getCreateBy());
        this.setUpdateTime(source.getUpdateTime());
        this.setUpdateBy(source.getUpdateBy());
    }

    public Post toPost() {
        Post target = new Post();
        target.setId(this.id);
        target.setOrgId(this.orgId);
        target.setName(this.name);
        target.setAlias(this.alias);
        target.setRemark(this.remark);
        target.setCreateTime(this.getCreateTime());
        target.setCreateBy(this.getCreateBy());
        target.setUpdateTime(this.getUpdateTime());
        target.setUpdateBy(this.getUpdateBy());
        return target;
    }
}
